<!--#include virtual="/dzps/p1.asp"-->
<script language="JScript" runat="Server">
    function ToObject(json) {
        var o;
        eval("o=" + json);
        return o;
    }

    function toArray(s) {
        var dic = Server.CreateObject("Scripting.Dictionary")
        eval("var a=" + json);
        for (var i = 0; i < a.length; i++) {
            var obj = Server.CreateObject("Scripting.Dictionary")
            for (x in a[i]) obj.Add(x, a[i][x])
            dic.Add(i, obj);
        }
        return dic
    }
</script>
<%
dim action,ret,sql,rs,json
json = request.form
action=Easp.Var("action")

dim myg_conn,myg_rs
if val("need_mysql")="1" then
	Easp.Db.SetConnection "myg", "MYSQL", "myg", "root:@"
	Set myg_conn =  Easp.Db.GetConnection("myg")
end if

select case action
	case "tl_post" tl_post
	case "prj_del_sel" prj_del_sel
	case "log1_add" 	log1_add	
	case "log1_add2" 	log1_add2
	case "equipmentType_l" 	equipmentType_l
	case "prn_l" 	prn_l
	case "prn_upd" 	prn_upd
	case "prn_add" 	prn_add
	case "prn_del" 	prn_del
	case "equipmentType_add"		equipmentType_add
	case "equipmentType_del"		equipmentType_del
	case "equipmentType_upd"		equipmentType_upd
	case "log1_l"		log1_l
	case "log1_del"		log1_del
	case "log1_upd"		log1_upd
	case "status_l"		status_l
	case "status_add"		status_add
	case "status_upd"		status_upd
	case "status_del"		status_del
	case "typ_l" 	typ_l
	case "eqi_l" 	eqi_l
	case "typ_add" 		typ_add
	case "typ_upd"		typ_upd
	case "typ_del"		typ_del
	case "eqi_add" 		eqi_add
	case "eqi_upd"		eqi_upd
	case "eqi_del"		eqi_del		
	case "user_typ_l"		user_typ_l
	case "user_typ_add"		user_typ_add
	case "user_typ_upd"		user_typ_upd
	case "user_typ_del"		user_typ_del
	case "log1_tlp_add"		log1_tlp_add
	case "test"		test
	case "compute_log1"		compute_log1
	case "xd_add2"		xd_add2
	case "log1_sum" log1_sum
	case "log1_overtime_l" log1_overtime_l
	case "log1_overtime_send" log1_overtime_send
	case "log1_qmess" log1_qmess
	Case "tzp_l" tzp_l
	Case "tzp_add"	tzp_add
	case "tzp_del" tzp_del
	case "tzp_upd" tzp_upd
	
	case "tzp_del_sel" tzp_del_sel
	case "div_test" div_test
	case "colla_data1" colla_data1
	case "div_data" div_data
	case "yj" yj
	case "yj_count" yj_count
	case "gen_yjxh" gen_yjxh
	case "del_yjxh" del_yjxh
	case "yj_upd" yj_upd
	case "pat_post_add"		pat_post_add
	Case "gz_post_add" gz_post_add
	case "div_data_declareTele"  	div_data_declareTele
	case "div_log0" 		div_log0
	case "div_data_reply" 		div_data_reply
	case "reply_post_add" 		reply_post_add
end select
function reply_post_add()
dim sqla(10)
	'vas2 "title",val("dept_code")
	
	sqla(0)=cr2("[tl_post]","log1_id,title")
	ret=execsw(sqla)
	rt ret
end function
function div_data_reply()
	dim i,arr
	's1 "select log1_id from tl_post where id={nid:int}"
	arr= sql2arr("select id,title,add_time,cover_path from tl_post where log1_id={log1_id:int} order by id desc")
	if ubound(arr)>0 then
		for i=0 to ubound(arr,2)
			echo myjs1("card_show.js","data-id|"& arr(0,i) &",card_title|" & arr(1,i) & "  " & "" &",card_p|"&  "<br>" & arr(3,i)& ",time|" & arr(2,i))
		next
	end if
end function
function div_log0()
	dim i,arr,img0,img1,img2,j
	arr= sql2arr("select submitTime,[declare],declareTele,questionDescription,a.id,pat_file,status,name1 from log0 a,baseinfo b where (1=1) and b.mode='科室' and a.questionDescription=b.name2 order by a.id desc")
	if ubound(arr)>0 then
		for i=0 to ubound(arr,2)
			select case arr(6,i)
				case "0" arr(6,i) = "待运行"
				case "1" arr(6,i) = "已完成"
			end select
			arr(6,i)=badge(arr(6,i),"blue")
			echo myjs1("card.js","data-id|"& arr(4,i) &",card_title|" & arr(6,i)  & "  " & arr(2,i) &",card_p|"&  "<br>" & arr(3,i) & "  " & arr(7,i) & " <br>  " & arr(5,i) & ",time|" & arr(0,i))
		next
	end if
end function
function gz_post_add()
	dim sqla(10)
	vas2 "questionDescription",val("dept_code")
	sqla(0)=cr2("[log0]","questionDescription")
	ret=execsw(sqla)
	rt ret
end function
function pat_post_add()
	if request("code")<>request.Cookies("AsaiCode") then
		rt2 0,"验证码不正确！"
		response.end
	end if
	dim sqla(10)
	sqla(0)=cr2("[log1]","declareTele,questionDescription,pat_file,status,typ")
	ret=execsw(sqla)
	rt ret
end function
function yj_upd()
	dim sqla(10),ret
	vas "pd2_id",val("xh")
	s1 "select xh from pd2 where id="&val("pd2_id")
	vas "id",val("id")
	sqla(0)=xg("[pd]","xh","id={id:int}")
	vas "pid",val("id")
	sqla(1)=xg("[pd2]","pid","id={pd2_id:int}")
	ret=execsw(sqla)
	rt ret	
end function
function div_data_declareTele()
	dim i,arr,img0,img1,img2,j
	arr= sql2arr("select submitTime,[declare],declareTele,questionDescription,id,pat_file from log1 where declareTele={declareTele} order by id desc")
	if ubound(arr)>0 then
		for i=0 to ubound(arr,2)
			img0=split(arr(5,i),",")
			if ubound(img0)>=1 then
				img1=""
				for j=0 to ubound(img0)
					img2="http://ab.yjk99.net/dzps/upload/"  & img0(j) 
					img1="<a href='" & img2 & "'" &  "target='_blank'>"  & "<img src='"  & img2  & "' class='layui-upload-img'></a>" &img1
				next 
				arr(5,i)=img1
			else
				arr(5,i)="http://ab.yjk99.net/dzps/upload/"  & arr(5,i) 
				arr(5,i)="<a href='" & arr(5,i) & "'" &  "target='_blank'>"  & "<img src='"  & arr(5,i)  & "' class='layui-upload-img'></a>"			
			end if
			echo myjs1("card.js","data-id|"& arr(4,i) &",card_title|" & arr(1,i) & "  " & arr(2,i) &",card_p|"&  "<br>" & arr(3,i)& " <br>  " & arr(5,i) & ",time|" & arr(0,i))
		next
	end if
end function
function div_data()
	dim i,arr
		arr= sql2arr("select submitTime,[declare],declareTele,questionDescription,id from log1 where equipmentId={equipmentId:int} order by id desc")
		if ubound(arr)>0 then
			for i=0 to ubound(arr,2)
				echo myjs1("card.js","data-id|"& arr(4,i) &",card_title|" & arr(1,i) & "  " & arr(2,i) &",card_p|"&  "<br>" & arr(3,i)& ",time|" & arr(0,i))
			next
		end if
end function
function colla_data1()
	dim i,arr,title_
		arr= sql2arr("select submitTime,[declare],declareTele,questionDescription,id from log1 where equipmentId={equipmentId:int} order by id desc")
	if val("tab")="1" then
		if ubound(arr)>0 then
			for i=0 to ubound(arr,2)
		title_=left(arr(3,i),12)
		echo colla(title_,myjs1("card.js","data-id|"& arr(4,i) &",card_title|" & arr(1,i) & "  " & arr(2,i) &",card_p|"&  "<br>" & arr(3,i)& ",time|" & arr(0,i)))
			next
		end if
	else
		if ubound(arr)>0 then
			for i=0 to ubound(arr,2)
				title_=left(arr(3,i),12)
				echo colla(title_,myjs1("timeline.html","timeline-title|"&arr(0,i) &",timeline-content|"& arr(1,i) & arr(2,i) & "<br>" & arr(3,i)))
			next
		end if
	end if
end function
function yj_count()
	dim i,arr,title_
	sql="select id,rq,noon,xh,pid,bz1,bz2,bz3,pdfj,ly,djzt from pd where (1=1) and (2=2) and (3=3) and (4=4)"
	if val("log1_search")<>"" then
	sql=replace(sql,"1=1","bz1 " & lbfh(val("log1_search")))
	end if  
	if val("pdfj")<>"" then
	s1 "select name1 as pdfj from baseinfo where id="&val("pdfj")
	sql=replace(sql,"2=2","pdfj "& lbfh(val("pdfj")))
	end if
	if val("sd")<>"" then
		sql=replace(sql,"3=3","bz2 >= '"& val("sd") &" 00:00:00'" & " and bz2<='"&val("ed")&" 23:59:59'")
	end if
	if val("djzt")<>"" then
		s1 "select name1 as djzt from baseinfo where id="&val("djzt")
		sql=replace(sql,"4=4","djzt={djzt}")
	end if
	echo rc(sql)
end function
  function del_yjxh()
    dim zxh,ylh,i,result,sql
    ylh="1,5,10,15,20"
    echo "----"
    sql="delete from pd2 where pdfj={pdfj} and appoint_date={appoint_date} and appoint_noon={appoint_noon}"
	result=easp.db.query(sql)
	echo result
  end function
  function gen_yjxh()
    dim zxh,ylh,i,result,sql
    ylh="1,5,10,15,20"
    zxh=cint(val("zxh"))

	for i=1 to zxh
      vas "xh",cstr(i)
      sql=cr2("pd2","pdfj,xh,appoint_noon,appoint_date")
	  result=easp.db.query(sql)
	  if result then 
	  	echo i & "   成功<br>"
	  else 
	  	echo i & "————————失败—————————— <br>"
	  end if
	next
  end function
function yj()
	dim i,arr,title_
	sql="select id,rq,noon,xh,pid,bz1,bz2,bz3,pdfj,ly,djzt,appoint_date,appoint_noon from pd where (1=1) and (2=2) and (3=3) and (4=4)"
	if val("log1_search")<>"" then
	sql=replace(sql,"1=1","bz1 " & lbfh(val("log1_search")))
	end if  
	if val("pdfj")<>"" then
	s1 "select name1 as pdfj from baseinfo where id="&val("pdfj")
	sql=replace(sql,"2=2","pdfj "& lbfh(val("pdfj")))
	end if
	if val("sd")<>"" then
		sql=replace(sql,"3=3","bz2 >= '"& val("sd") &" 00:00:00'" & " and bz2<='"&val("ed")&" 23:59:59'")
	end if
	if val("djzt")<>"" then
		s1 "select name1 as djzt from baseinfo where id="&val("djzt")
		sql=replace(sql,"4=4","djzt={djzt}")
	end if
	'echo sql
	blockquote("记录总数：" & rc(sql) & "，每页记录数："& Easp.Db.PageSize&"，当前第 "& val("page") & "页")
	arr=sql2arr2(sql)
	if ubound(arr)>0 then
		for i=0 to ubound(arr,2)
			if arr(9,i)="门诊" then
		title_=badge(arr(9,i),"") 
		else
		title_=badge(arr(9,i),"blue") 
		end if
		title_=title_  & arr(1,i) & " " & arr(2,i) & " 卡号：" & arr(4,i)&" 姓名："&arr(5,i) & " " &arr(7,i)
			arr(10,i)=badge(arr(10,i),"")
		echo myjs1 ("log1_div.html","status|"  & arr(10,i) &" "& arr(8,i) &",truename|"& "" & ",data-id|"& arr(0,i) & ",content|"&title_&",time|序号： "& arr(3,i)&"  预约时间："&arr(11,i)&" 处方时间："&arr(6,i) )
		next
	end if
end function

function div_test()
	dim i,arr,title_,typ_name,ans,fxpwd,code_c,flds,truename,id,submitTime
	flds="id,questionDescription,[declare],declareTele,submitTime,[status],typ,typ_name,repairerId,truename,fxpwd,ans,title1"

	sql="select "&flds&" from v_log1   where (1=1) and (2=2) order by id desc"
	if val("log1_search")<>"" then
		sql=replace(sql,"1=1","questionDescription "& hr_b(val("log1_search")) &" or fxpwd " &hr_b(val("log1_search")))
	end if
	if val("status")<>"" then
		sql=replace(sql,"2=2","status= "& val("status") )
	end if	
  	arr= sql2arr2(sql)
	if ubound(arr)>0 then
		fld_idx flds
		delimiter="|lse|"
		for i=0 to ubound(arr,2)
			id=arr(ival("id"),i)
			code_c=left(arr(ival("questionDescription"),i),55)
			title_=arr(ival("title1"),i)
			typ_name=badge(arr(ival("typ_name"),i),"blue")
			ans="答案："& arr(ival("ans"),i)

			fxpwd=easp.str.HtmlFilter(arr(ival("fxpwd"),i))
			fxpwd=left(fxpwd,150)
			
			truename=arr(ival("truename"),i)
			submitTime=arr(ival("submitTime"),i)
			echo myjs1 ("log1_div.html","title"&delimiter&title_& ",status"&delimiter & code_c &",truename"&delimiter& truename & ",data-id"&delimiter& id  & ",content"&delimiter&fxpwd&",time"&delimiter &ans&"<br>" &  typ_name & "<br>" & submitTime)
		next
	end if	
end function
Function tzp_del_sel()
	dim result,ob,i,ids,ret
	Set ob = toArray(json)
	For i=0 To ob.Count-1
		easp.var("id")=ob(i)("id")
		ret = Easp.Db.del("tzp","id={id:int}")
	next
	Set ob = Nothing
End Function
Function tzp_upd()
	dim sqla(10)
	vas "id",val(hr_1("id")) 
	sqla(0)=xg2("[tzp]","[title],cover_path,description,content","id={id:int}")
	ret=execsw(sqla)
	rt ret
End Function
Function tzp_del()
	dim ret
	ret = Easp.Db.Del("[tzp]","id={id:int}")
	rt ret
End Function
Function tzp_add()
	dim sqla(10)
	'vas hr_1("user_id"),session("user_id")
	sqla(0)=cr2("[tzp]","[title],cover_path,description,content")
	ret=execsw(sqla)
	rt ret
End Function
function tzp_l()
	dim sql,tn
	tn="tzp"
	sql="select id,title,cover_path,keywords,add_time,mod_time,pub_time,description,content,views,cat_id,user_id,allow_comment,is_display,is_delete,is_audit,comment_count,view_count,zan_count,cai_count,is_top,log1_id from tzp where (1=1) and (2=2)"
	if val(tn & "_search")<>"" then
		vas "likeKey" ,"%{="&tn&"_search}%"
		sql=replace(sql,"1=1","title like {likeKey} or cover_path like {likeKey}" )
	end if
	qry2json(sql)
end function
Function tl_post()
	dim sql
	' echo val("log1_id")
	sql="select a.id,a.add_time,title,user_id,b.username from tl_post a,[user] b where a.user_id=b.id and log1_id={log1_id:int} order by a.id desc"
	qry2json(sql)
end function
Function log1_overtime_l()
	dim sql,fields,tn
	tn="log1"
	sql="select * from (select count(log1.id) as cnt,[user].truename,[user].mobile from v_log1,[user]  where v_log1.repairerId=[user].id and (v_log1.[status]=899) and (1=1) and (2=2) and (3=3) and (5=5) and (6=6) group by [user].truename,[user].mobile ) "
	if val(tn & "_search")<>"" then
		vas "likeKey" ,"%{=log1_search}%"
		sql=replace(sql,"1=1","questionDescription like {likeKey} or truename like {likeKey}" )
	end if
	if val("typ")<>"" then
		sql=replace(sql,"2=2","typ = {typ}")
	end if
	if val("status")<>"" then
		sql=replace(sql,"3=3","status = {status}")
	end if
	if val("sd")<>"" and val("ed")<>"" then
		sql=replace(sql,"5=5","submitTime >= #"& val("sd")&" 00:00:00# "& " and " & "submitTime<=#"&val("ed") & " 23:59:59#")
	else
		vas "sd",Format_Time(now()-10,2)
		vas "ed",Format_Time(now()-3,2)
		sql=replace(sql,"5=5","submitTime >= #"& val("sd")&" 00:00:00# "& " and " & "submitTime<=#"&val("ed") & " 23:59:59#")
	end if
	if val("repairerId")="" then
		' vas "repairerId",session("user_id")
		' sql=replace(sql,"6=6","repairerId = {repairerId}")
	else
		sql=replace(sql,"6=6","repairerId = {repairerId}")
	end if
	qry2json(sql)
End Function
function log1_overtime_send()
	dim sql,arr,maxcol,maxrow,i,j,txt,ret
	sql="select * from (select count(log1.id) as cnt,[user].truename,[user].mobile from v_log1,[user]  where v_log1.repairerId=[user].id and (v_log1.[status]=899) and (6=6) group by [user].truename,[user].mobile ) "
	arr= sql2arr(sql)
	maxcol=ubound(arr,1)
	maxrow=ubound(arr,2)

	for i=0 to maxrow
		vas "phone",arr(2,i)
		vas "cnt",arr(0,i)
		txt="您有"& val("cnt") & "条超时工单。请及时处理！"
		vas "mess_text",txt
		send_mess val("phone"),val("txt")
	next	
	rt ret
end function
Function qry2json2(myg_conn1,sql)
	dim rs,rsjson,json,s
	dim a,b
	easp.db.pagesize = easp.var("limit")
	' set rs  = Easp.Db.GetRs(sql)
	set rs  = Easp.Db.GetRecordSet(myg_conn1, sql)
	
	Easp.Json.EncodeUnicode=false
	rsjson=Easp.Encode(rs)
	Easp.Db.Close(rs)
	set json=Easp.Decode(rsjson)
	json.put "total",easp.db.pagerecordcount

	s = json.toString()
	a =  instr(s,"[")
	b =  instr(s,"]")
	s = replace(s,"rows","data")
	s = replace(s,"total","count")
	
	echo replace(s,"{",  "{" & syh("code") & ":0,"  & syh("msg") & ":" & syh("") & ",",1,1)
	set json = nothing
End Function

function log1_qmess()
	sql="select * from mess where mysource=1 order by id desc"
	qry2json2 myg_conn,sql
end function

function myg()
	dim myg_rs
	Set myg_rs = Easp.Db.Execute(myg_conn, "select TIMESTAMPDIFF(MINUTE,end_time,now()) as tdmi from gh_run_status ORDER BY id desc LIMIT 1")
	myg=myg_rs(0)
	myg_rs.close
	set myg_rs=Nothing
end function

Function xd_add2()
	save_html val("log1_id"),val("content")
	rt 1
End Function
Function save_html(log1_id,content)
	dim conn3,rs1
	Set Conn3 = Easp.Db.GetConn
	sql = "select top 1 * from xd_p where log1_id="&log1_id
	Set rs = server.CreateObject("adodb.recordset")
	rs.open sql,conn3,1,3
	if rs.recordcount=0 then
		rs.addnew
	else
	end if
	rs("content")=content
	rs("log1_id")=val("log1_id")
	rs("user_id")=session("user_id")
	rs.update
	rs.Close
	Set rs = Nothing
End Function

sub compute_log1
	dim rc1,td,overtime
	rc1=rc("select id from [log1] where status=(select id from baseinfo where mode='工单状态' and name1='已处理' )")
	vas "done",rc1
	rc1=rc("select id from [log1] where status=(select id from baseinfo where mode='工单状态' and name1='处理中' )")
	vas "process",rc1	
	rc1=rc("select id from [log1] where status=(select id from baseinfo where mode='工单状态' and name1='未分配' )")
	vas "undistribute",rc1
	td = Format_Time(date(),2)
	rc1=rc("select id from [log1] where status=(select id from baseinfo where mode='工单状态' and name1='未分配') and (submitTime>=#" & td &" 00:00:00# and submitTime<=#" & td & " 23:59:59# )")
	vas "todayundistribute",rc1
	overtime=Format_Time(DateAdd("d",-2,now()),1) 
	rc1=rc("select id from [log1] where status=(select id from baseinfo where mode='工单状态' and name1='未分配') and (submitTime<=#" & overtime & "# )")
	vas "overtime",rc1
	vas "myg",myg()
	retJson "0","成功",dkh(json_help("done",val("done"))&","&json_help("myg",val("myg"))&","&json_help("todayundistribute",val("todayundistribute")) & "," & json_help("process",val("process")) & "," & json_help("undistribute",val("undistribute") ) & "," & json_help("overtime",val("overtime") )   )	
end sub

function json_help(key,value)
	dim txt
	txt= syh(key)&":"& value
	json_help=txt
end function
'card_post=id,title,cover_path,keywords,add_time,mod_time,pub_time,description,content,views,cat_id,user_id,allow_comment,is_display,is_delete,is_audit,comment_count,view_count,zan_count,cai_count,is_top,log1_id


Function test2()
	qry2json("select id,submitTime,[declare],declareTele,questionDescription from log1 where 1=1 order by id desc")
End Function
Function log1_tlp_add()
	dim sqla(10)
	vas hr_1("user_id"),session("user_id")
	sqla(0)=cr2("[tl_post]","title,log1_id,user_id")
	ret=execsw(sqla)
	rt ret
End Function

Function user_typ_add()
	dim sqla(10)
	vas hr_1("mode"),"用户类型"
	sqla(0)=cr2("[baseinfo]","name1,mode")
	ret=execsw(sqla)
	rt ret
End Function
Function user_typ_upd()
	dim sqla(10)
	vas "id",val(hr_1("id")) 
	sqla(0)=xg2("[baseinfo]","name1","id={id:int}")
	ret=execsw(sqla)
	rt ret
End Function
Function user_typ_del()
	dim ret
	ret = Easp.Db.Del("[baseinfo]","id={id:int}")
	rt ret
End Function
Function user_typ_l()
	sql="select id,name1 from baseinfo  where (1=1) and (mode='用户类型')"
	if val("user_typ_search")<>"" then
		vas "likeKey" ,"%{=user_typ_search}%"
		sql=replace(sql,"1=1","name1 like {likeKey}")
	end if
	qry2json(sql)
end function
Function eqi_add()
	dim sqla(10)
	vas hr_1("mode"),"设备类型"
	sqla(0)=cr2("[baseinfo]","name1,mode")
	ret=execsw(sqla)
	rt ret
End Function
Function eqi_upd()
	dim sqla(10)
	vas "id",val(hr_1("id")) 
	sqla(0)=xg2("[baseinfo]","name1","id={id:int}")
	ret=execsw(sqla)
	rt ret
End Function
Function eqi_del()
	dim ret
	ret = Easp.Db.Del("[baseinfo]","id={id:int}")
	rt ret
End Function
Function eqi_l()
	sql="select id,name1 from baseinfo  where (1=1) and (mode='设备类型')"
	if val("eqi_search")<>"" then
		vas "likeKey" ,"%{=eqi_search}%"
		sql=replace(sql,"1=1","name1 like {likeKey}")
	end if
	qry2json(sql)
end function
Function typ_add()
	dim sqla(10)
	vas hr_1("mode"),"工单类型"
	sqla(0)=cr2("[baseinfo]","name1,mode")
	ret=execsw(sqla)
	rt ret
End Function
Function typ_upd()
	dim sqla(10)
	vas "id",val(hr_1("id")) 
	sqla(0)=xg2("[baseinfo]","name1","id={id:int}")
	ret=execsw(sqla)
	rt ret
End Function
Function typ_del()
	dim ret
	ret = Easp.Db.Del("[baseinfo]","id={id:int}")
	rt ret
End Function
Function typ_l()
	sql="select id,name1 from baseinfo  where (1=1) and (mode='工单类型')"
	if val("typ_search")<>"" then
		vas "likeKey" ,"%{=typ_search}%"
		sql=replace(sql,"1=1","name1 like {likeKey}")
	end if
	qry2json(sql)
end function
Function status_add()
	dim sqla(10)
	vas hr_1("mode"),"工单状态"
	sqla(0)=cr2("[baseinfo]","name1,mode")
	ret=execsw(sqla)
	rt ret
End Function
Function status_upd()
	dim sqla(10)
	vas "id",val(hr_1("id")) 
	sqla(0)=xg2("[baseinfo]","name1","id={id:int}")
	ret=execsw(sqla)
	rt ret
End Function
Function status_del()
	dim ret
	ret = Easp.Db.Del("[baseinfo]","id={id:int}")
	rt ret
End Function
Function status_l()
	sql="select id,name1 from baseinfo  where (1=1) and (mode='工单状态')"
	if val("status_search")<>"" then
		vas "likeKey" ,"%{=status_search}%"
		sql=replace(sql,"1=1","name1 like {likeKey}")
	end if
	qry2json(sql)
end function

Function prn_del()
	dim ret
	ret = Easp.Db.Del("[equipment]","id={id:int}")
	rt ret
End Function
Function prn_add()
	dim sqla(10),rc1
	vas "machineNo",val("machineNo")
	rc1= rc("select id from [equipment] where machineNo={machineNo}")
	'val("machineNo")<>"" 用于没有机器号的情况
	if rc1=1 and val("machineNo")<>"" then 
		s1 "select id as id1 from [equipment] where machineNo={machineNo}"
		rt2 0,"machineNo 机器号" & val("machineNo") & " 重复id=" & val("id1")
	else
		sqla(0)=cr2("[equipment]","department,[local],machineNo,equipmentTypeId,ipadr")
		ret=execsw(sqla)
		rt ret		
	end if	
End Function
Function log1_del()
	dim sqla(10),rc1
	ret = Easp.Db.Del("[log1]","id={id:int}")
	ret=execsw(sqla)
	rt ret
End Function
Function log1_add2()
	dim sqla(10)
	sqla(0)=cr2("[log1]","[declare],declareTele,questionDescription,typ,status,repairerId,fxpwd")
	ret=execsw(sqla)
	rt ret
	
	if val("sendmess")="on" then
		vas "repairerId",val("repairerId")
		s1 "select mobile from [user] where id={repairerId}"
		vas "mess_text","收到工单:"& val("questionDescription") & " 来自：" & val("declare") & val("declareTele")  &  "，请及时处理。"
		vas "phone",val("mobile")
		send_mess val("phone"),val("mess_text")
	end if
End Function
Function log1_add()
	if request("code")<>request.Cookies("AsaiCode") then
		rt2 0,"验证码不正确！"
		response.end
	end if
	dim sqla(10)
	vas2 "questionDescription",replace(val("questionDescription"),"'","‘")
	sqla(0)=cr2("[log1]","equipmentId,[declare],declareTele,questionDescription,typ,status")
	ret=execsw(sqla)
	rt ret
	
	vas "mess_text","您的工单提交成功，信息科将及时处理。"
	vas "phone",val("declareTele")
	send_mess val("phone"),val("mess_text")
	' response.end
	vas "mess_text","收到工单:"& val("questionDescription") & " 来自：" & val("declare") & val("declareTele")  &  "，请及时处理。"
	vas "phone",val("mobile")
	send_mess val("phone"),val("mess_text")
End Function


Function send_mess(phone,mess_text)
	dim sql,ret
	vas "date",Format_Time(now(),2)
	vas "mysource","1"

	vas "phone",phone
	vas "mess_text",mess_text
	sql=cr("mess","phone,mess_text,date,mysource")
	ret= Easp.Db.Execute(myg_conn, sql)
	send_mess=ret
end function
Function log1_upd()
	dim sqla(10),rc1
	vas "id",val(hr_1("id"))
	vas2 "questionDescription",replace(val("questionDescription"),"'","‘")

	sqla(0)=xg2("[log1]","status,typ,repairerId,questionDescription,fxpwd","id={id:int}" )
	vas "status",val(hr_1("status"))
	vas "repairerId",val(hr_1("repairerId"))
	s1 "select name1 as status from baseinfo where id={status:int}"
	s1 "select truename from [user] where id={repairerId:int}"
	
	vas "title",session("username") & "把状态改为：" & val("status") & "，把接单人改为：" & val("truename")
	vas "log1_id",val("id")
	if (rc("select id from tl_post where title={title} and log1_id={log1_id:int}" )=0) then
		vas "user_id",session("user_id")
		sqla(1)=cr("[tl_post]","title,log1_id,user_id")
	end if
	ret=execsw(sqla)
	rt ret

	if val("sendmess")="on" then
		s1 "select mobile from [user] where id={repairerId}"
		vas "mess_text","系统收到一条工单"& val("questionDescription") & "，请及时处理。"
		vas "phone",val("mobile")
		send_mess val("phone"),val("mess_text")
	end if
End Function
Function prn_upd()
	dim sqla(10),rc1
	vas "id",val(hr_1("id"))
	vas "machineNo",val(hr_1("machineNo"))
	rc1= rc("select id from [equipment] where machineNo={machineNo}")
	if rc1>1 then
		rt 0,"machineNo 机器号" & val(hr_1("machineNo")) & " 重复"
	else
		sqla(0)=xg2("[equipment]","department,[local],machineNo,equipmentTypeId,ipadr","id={id:int}" )
		ret=execsw(sqla)
		rt ret
	end if
End Function
Function equipmentType_del()
	dim ret
	ret = Easp.Db.Del("[equipmentType]","id={id:int}")
	rt ret
End Function
Function equipmentType_upd()
	dim sqla(10),rc1
	vas "id",val(hr_1("id"))
	rc1= rc("select id from [equipmentType] where equipmentName={equipmentName}")
	if rc1>1 then
		rt 0,"equipmentName 打印机型号" & val(hr_1("equipmentName")) & " 重复"
	else
		sqla(0)=xg2("[equipmentType]","equipmentName,typ","id={id:int}")
		ret=execsw(sqla)
		rt ret		
	end if	
End Function
Function equipmentType_add()
	dim sqla(10),rc1
	rc1= rc("select id from [equipmentType] where equipmentName={equipmentName}")
	if rc1=1 then
		rt 0,"equipmentName 打印机型号" & val(hr_1("equipmentName")) & " 重复"
	else
		sqla(0)=cr2("[equipmentType]","equipmentName,typ")
		ret=execsw(sqla)
		rt ret		
	end if	
End Function
Function equipmentType_l()
	dim sql,fields
	sql="select * from equipmentType  where (1=1)"
	if val("equipmentType_search")<>"" then
		vas "likeKey" ,"%{=equipmentType_search}%"
		sql=replace(sql,"1=1","equipmentName like {likeKey}")
	end if
	qry2json(sql)
End Function
Function test()
	dim sql,arr
	sql="select questionDescription from log1 where questionDescription like '*''*'"
	' arr= sql2arr(sql)
	' sql="update log1 set questionDescription=replace(questionDescription,'''','’') where questionDescription like '*''*'"
	' execsw sql

end function

Function log1_sum()
	dim sql
	easp.db.del "temp_sum1","1=1"
	sql= "select distinct truename from v_log1"
	gen_temp_sum0 sql
	
	sql="select truename,count(id) as cnt1 from v_log1 where status=899 group by truename"
	gen_temp_sum sql,"cnt1"

	sql="select truename,count(id) as cnt2 from v_log1 where status=900 group by truename"
	gen_temp_sum sql,"cnt2"

	sql="select truename,count(id) as cnt2 from v_log1 where status=1032 group by truename"
	gen_temp_sum sql,"cnt3"	
	
	sql="select * from temp_sum1 order by cnt1 desc"
	qry2json(sql)
End Function
Function gen_temp_sum0(sql)
	dim arr,i,maxcol,maxrow,j
	arr=sql2arr(sql)
	maxcol=ubound(arr,1)
	maxrow=ubound(arr,2)

	for i=0 to maxrow
		for j=0 to maxcol
			vas "truename",arr(j,i)
			sql=cr("temp_sum1","truename")
			execsw sql
		next
	next
End function

Function gen_temp_sum(sql,fieldn)
	dim arr,maxcol,maxrow,i,j
	arr=sql2arr(sql)
	maxcol=ubound(arr,1)
	maxrow=ubound(arr,2)
	for i=0 to maxrow
		vas "truename",arr(0,i)
		vas fieldn,arr(1,i)
		sql=xg("temp_sum1",fieldn,"truename={truename}")
		execsw sql
	next
End function


Function log1_l()
	dim sql,fields,tn
	tn="log1"
	sql="select id,equipmentId,repairerId,questionDescription,[declare],declareTele,submitTime,[status],name1,equipmentname,typ,typ_name,repairerId,truename from v_log1  where (1=1) and (2=2) and (3=3) and (5=5) and (6=6) order by id desc"
	if val(tn & "_search")<>"" then
		vas "likeKey" ,"%{=log1_search}%"
		sql=replace(sql,"1=1","questionDescription like {likeKey} or truename like {likeKey}" )
	end if
	if val("typ")<>"" then
		sql=replace(sql,"2=2","typ = {typ}")
	end if
	if val("status")<>"" then
		sql=replace(sql,"3=3","status = {status}")
	end if
	if val("sd")<>"" and val("ed")<>"" then
		sql=replace(sql,"5=5","submitTime >= #"& val("sd")&" 00:00:00# "& " and " & "submitTime<=#"&val("ed") & " 23:59:59#")
	else
		vas "sd",Format_Time(now()-5,2)
		vas "ed",Format_Time(now(),2)
		sql=replace(sql,"5=5","submitTime >= #"& val("sd")&" 00:00:00# "& " and " & "submitTime<=#"&val("ed") & " 23:59:59#")
	end if
	if val("repairerId")="" then
		' vas "repairerId",session("user_id")
		' sql=replace(sql,"6=6","repairerId = {repairerId}")
	else
		sql=replace(sql,"6=6","repairerId = {repairerId}")
	end if
	qry2json(sql)
End Function

Function prn_l()
	dim sql,fields
	sql="select id,department,[local],machineNo,equipmentTypeId,equipmentName,ipadr from v_prn  where (1=1) and (2=2)"
	if val("prn_search")<>"" then
		vas "likeKey" ,"%{=prn_search}%"
		sql=replace(sql,"1=1","department like {likeKey}")
	end if
	if val("typ")<>"" then
		sql=replace(sql,"2=2","typ = {typ}")
	else
        s1 "select id as typ from baseinfo where mode='设备类型'"
		sql=replace(sql,"2=2","typ = {typ}")
	end if

	qry2json(sql)
End Function
Function prj_del_sel()
	dim result,ob,i,ids,ret
	Set ob = toArray(json)
	For i=0 To ob.Count-1
		easp.var("id")=ob(i)("id")
		ret = Easp.Db.del("prj","id={id:int}")
	next
	Set ob = Nothing
End Function

Function getCheckData()
	dim result,ob,i,ids
	Set ob = toArray(json)
	For i=0 To ob.Count-1
	  ids=ids&ob(i)("ID") & "," 
	next
	easp.var("ids")=left(ids,len(ids)-1)
	Set ob = Nothing	
	result=easp.db.del("jf","id in ({ids})")
End Function
Function batchQrjf()
	dim result,ob,i,ids,ret
	Set ob = toArray(json)
	For i=0 To ob.Count-1
		' ids=ids&ob(i)("ID") & "," 
		easp.var("id")=ob(i)("ID")
		set rs=easp.db.sel("select qrjf from [jf] where id={id}")
		if rs("qrjf")=0 then
			ret=Easp.Db.Upd ("[jf]","qrjf=1","id={id}")    	
		end if
	next
	Set ob = Nothing
End Function
%>